// 提交链接：https://leetcode.cn/problems/find-the-town-judge/description/
// lc1629. 按键持续时间最长的键
// 完成日期：2024/11/20
// c++ 字符串 数组

class Solution {
public:
    char slowestKey(vector<int>& releaseTimes, string keysPressed) {
        int n = releaseTimes.size();
        char ans = keysPressed[0];
        int k = 0,min = 0;
        for(int i = 0; i < n; ++i)
        {
            if(i == 0)
                min = releaseTimes[0];
            else
            {
                k = releaseTimes[i] - releaseTimes[i-1];
                if(k > min || (k == min && keysPressed[i] > ans))
                {
                    min = k;
                    ans = keysPressed[i];
                }
            } 
        }
        return ans;
    }
};